package cn.yuhh.api.v1.common;


import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.helper.IDataToMap;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.domain.AreaInfo;
import cn.yuhh.core.type.Status;
import com.magic.spring.mongo.Mongo;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ysw
 * @create 2020-02-25 15:38
 * @descreption 获取区域信息
 **/
@Component("listAreaInfo1.0")
public class ListAreaInfo extends AbstractApiService {
    Map map = new HashMap();
    @Override
    public Map service(Map request) {
        if(map.isEmpty()){
            List<AreaInfo> areaInfoList = Mongo.buildMongo().eq("status", Status.ACTIVE).findAll(AreaInfo.class);
            map = ApiResponse.success(areaInfoList, new IDataToMap<AreaInfo>() {
                @Override
                public void dataToMap(Map map, AreaInfo source) {
                    map.put("countyCode", source.getCountyCode());
                    map.put("county", source.getCounty());
                }
            });
        }
        return map;
    }
}
